package com.kay;

import com.kay.server.RPCServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Description:
 * @Author: Kay
 * @CreateDate: 2021/8/27$ 19:14$
 * @UpdateUser: Kay
 * @UpdateDate: 2021/8/27$ 19:14$
 */
@SpringBootApplication
public class ServerApplication implements CommandLineRunner {
    @Autowired
    private RPCServer rpcServer;

    @Value("${rpc.server1.ip}")
    private String ip1;

    @Value("${rpc.server1.port}")
    private int port1;

    @Value("${rpc.server2.ip}")
    private String ip2;

    @Value("${rpc.server2.port}")
    private int port2;

    @Value("${rpc.server3.ip}")
    private String ip3;

    @Value("${rpc.server3.port}")
    private int port3;

    public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);

    }

    @Override
    public void run(String... args) throws Exception {
        new Thread(new Runnable() {
            @Override
            public void run() {
                rpcServer.startServer(ip1, port1);
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                rpcServer.startServer(ip2, port2);
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                rpcServer.startServer(ip3, port3);
            }
        }).start();
    }
}
